﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using gg;

namespace ggUI.UnitTests
{
    class TestQuickParser
    {
            //userInput,expected desc,expected tag,expected time, describe test  
        static string[,] tests = new string[,] { 
                {"smell feet", "smell feet", "misc", DateTime.MinValue.ToString(), "simple"},
                {"smell feet #smell", "smell feet", "smell", DateTime.MinValue.ToString(), "tag"},
                {"smell feet #", "smell feet", "misc", DateTime.MinValue.ToString(), "empty tag"},
                {"smell feet by tmr", "smell feet", "misc", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).ToString(), "tmr test"},
                {"smell feet by tmr #smell", "smell feet", "smell", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).ToString(), "tmr test with tag"},
                {"smell feet by tmr 5pm", "smell feet", "misc", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time"},
                {"smell feet by 5pm tmr", "smell feet", "misc", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time swapped"},
                {"smell feet by tmr 2359", "smell feet", "misc", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(23).AddMinutes(59).ToString(), "tmr test with time"},
                {"smell feet by tmr 5pm #smell", "smell feet", "smell", DateTime.Parse(DateTime.Now.AddDays(1).ToShortDateString()).AddHours(17).ToString(), "tmr test with time and tag"},
                {"smell 2011 cups of coffee", "smell 2011 cups of coffee", "misc", DateTime.MinValue.ToString(), "missing date and time"},
                {"smell feet by 17/09/2011", "smell feet", "misc", DateTime.Parse("09/17/2011").ToString(), "specific date"},
                {"smell feet by 17/09", "smell feet", "misc", DateTime.Parse("09/17/2011").ToString(), "short date"},
                {"smell feet by 17-9", "smell feet", "misc", DateTime.Parse("09/17/2011").ToString(), "short date variation"},
                {"smell feet by 17-9 5pm", "smell feet", "misc", DateTime.Parse("09/17/2011").AddHours(17).ToString(), "short date and time"},
                {"smell feet by this sun 5pm", "smell feet", "misc", DateTime.Parse("10/30/2011").AddHours(17).ToString(), "next week and time"},
                {"smell this smelly feet", "smell this smelly feet", "misc", DateTime.MinValue.ToString(), "to confuse"},
                {"read book #book by 11 feb", "read book", "book", DateTime.Parse("02/11/2011").ToString(), "natural date"},
                {"read book #book by oct", "read book", "book", DateTime.Parse("10/1/2011").ToString(), "natural month only"},
                {"read book #book 11 oct", "read book", "book", DateTime.Parse("10/11/2011").ToString(), "without by"},
                {"read book #book sun 5pm", "read book", "book", DateTime.Parse("10/30/2011").AddHours(17).ToString(), "natural weekday without by"}
        };
        public TestQuickParser()
        {

            int passed = 0;

            for (int i = 0; i < (tests.Length / 5); i++)
            {
                testParser(i);
                passed++;
            }
            Console.WriteLine("QuickParser passed test cases = " + passed);
        }

        static void testParser(int index)
        {
            GGItem gg = QuickParser.Parse(tests[index, 0]);
            assert(gg.GetDescription(), tests[index, 1], tests[index, 4] + " description");
            assert(gg.GetTag(), tests[index, 2], tests[index, 4] + " tag");
            assert(gg.GetEndDate().ToString(), tests[index, 3], tests[index, 4] + " datetime");
        }

        static void assert(string expected, string actual, string message)
        {
            if (!expected.Equals(actual))
            {
                Console.WriteLine(string.Format("{0} failed!\n {1} != {2}", message, expected, actual));
                Console.ReadLine();
                Environment.Exit(1);
            }
        }
    }
}
